﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SeniorGeneric
{
    class Store<T>
    {
        private T[] arr = new T[100];

        public T[] Arr { get { return arr; } }
        public void Put(T v, int index)
        {
            arr[index] = v;
        }
    }

    class StoreData<T, U>
    {
        public T[] arr0 { set; get; }
        public U[] arr1 { set; get; }
    }


    class Person<T>
    {
        public int id { set; get;}
    }
    //1.将父类进行特化，然后继承
    class Teacher:Person<int>
    {
    }
    //2.子类继承父类作为泛型
    class Teachers<T, U> : Person<U>
    {
        public T name {  set; get; }
    }


    internal class Program
    {
        static void Main(string[] args)
        {

            int a = 12; int b = 13;
            float c = 12.1f; float d = 13.1f;
            Store<int> s = new Store<int>();
            s.Put(1, 0);
            Console.WriteLine(s.Arr[0]);
            Swap<int>(ref a, ref b);
            Swap<float>(ref c, ref d);
            //特化arr0和arr1
            StoreData<int,float> storeData = new StoreData<int,float>();
            //特化Teachers
            Teachers<string, int> teacher = new Teachers<string, int>();
            Console.WriteLine(a);
            Console.WriteLine($"{c}");
            Console.WriteLine($"{Add<float>(c, d)}");
        }

        public static void Swap<T>(ref T a, ref T b)
        {
            T temp = a;
            a = b;
            b = temp;
        }

        public static T Add<T>(T a, T b)
        {
            dynamic? da = a;
            dynamic? db = b;
            return da + db;
        }
    }
}
